package modelLayer;
import java.util.ArrayList;

/**
 * Liste over dvder i programmet
 * og administrering af dvder
 * 
 * 
 */
public class DVDContainer
{
    ArrayList<DVD> DVDList;
    private static DVDContainer instance;
    /**
     * Constructor for objects of class DVDContainer
     */
    private DVDContainer()
    {
        DVDList = new ArrayList<DVD>();
    }
    public static DVDContainer getInstance()
    {
        if(instance == null) 
        {
            instance = new DVDContainer();
        }
        return instance;
    }
    public void addDVD(DVD dvd)
    {
        DVDList.add(dvd);
    }
    public DVD findDVD(String title)
    {
        DVD DVDToReturn = null;
        boolean found = false;
        int i = 0;
        while(!found && i < DVDList.size())
        {   
            DVD dvd = DVDList.get(i);
            if(dvd.getTitle().equals(title))
            {
                DVDToReturn = dvd;
                found = true;
            }
            i++;
        }   
        return DVDToReturn;
    }
    
    public Copy findCopy(String serialNumber)
    {
        Copy copyToReturn = null;
        boolean found = false;
        int i = 0;
        while(!found && i < DVDList.size())
        {   
            DVD dvd = DVDList.get(i);
            copyToReturn = dvd.findCopy(serialNumber);
            if(copyToReturn != null)
                found = true;
            i++;
        }   
        return copyToReturn;
    }
    
    public void removeDVD(DVD dvd)
    {
        DVDList.remove(dvd);
    }
}